/**
 * 复制文字控件
 */
define(function (require) {
    require('angular-mocks');
    require('static_public/js/angular_directive/clipboard');

    describe('clipboard', function () {
        var scope, element, $document, clip;
        beforeEach(module('angular.directive.clipboard'));
        beforeEach(function (done) {
            inject(function ($rootScope, _$compile_, _$document_) {
                $document = _$document_;

                scope = $rootScope.$new(true);
                element = angular.element('<div clipboard clip="clip" content="content" aftercopy="afterCopy()"></div>');
                _$document_.find('body').append(element);

                _$compile_(element)(scope);
                scope.$digest();

                scope.afterCopy = function(){console.info('afterCopy')};

                spyOn(scope, 'afterCopy');

                clip = scope.clip;
                clip.on("ready", function () {
                    done();
                });
            });
        });

        afterEach(function () {
            clip.destroy();
            clip = null;

            scope.$destroy();
            scope = null;
        });

        it('初始化', function (done) {
            expect($document.find('#global-zeroclipboard-html-bridge')[0]).not.toBeNull();

            done();
        });

        it('赋值', function (done) {
            var content = 'html文字1231132';

            scope.content = content;
            scope.$digest();

            expect(element.attr('data-clipboard-text')).toEqual(content);
            expect(element.data('clipboard-text')).toEqual(content);

            done();
        });

        it('复制动作', function (done) {
            element[0].dispatchEvent(new MouseEvent('mouseover'));
            expect(parseFloat($document.find('#global-zeroclipboard-html-bridge').css('top'))).toBeGreaterThan(0);

            clip.emit({type:'copy'});

            expect(scope.afterCopy).toHaveBeenCalled();

            done();
        });
    });
});